<html>
    <head>
    </head>
    <body>
        <script type="text/javascript" src="jquery.js"></script>

        <script>
        var cookie = "No cookie";

        function register(user, pass)
        {
            $.post('http://wadobo.com:8082/register',
                { user: user, password: pass }, register_res);
        }

        function register_res(data)
        {
            res = JSON.parse(data);
            if (res.status == "error")
            {
                alert("Error: " + res.message);
            }
            else if (res.status == "ok")
            {
                cookie = res.cookie;
                alert('Registrado: ' + cookie);
            }
        }

        function auth(user, pass)
        {
            $.post('http://wadobo.com:8082/auth',
                { user: user , password: pass }, auth_res);
        }

        function auth_res(data)
        {
            res = JSON.parse(data);
            if (res.status == "error")
            {
                alert("Error: " + res.message);
            }
            else if (res.status == "ok")
            {
                cookie = res.cookie;
                alert('Autenticado: ' + cookie);
            }
        }

        function show_cookie()
        {
            alert("Cookie: " + cookie);
        }

        function get_all_passwords()
        {
            $.post('http://wadobo.com:8082/get_all_passwords',
                {cookie: cookie}, standard_response());
        }

        function onRequest(request, sender)
        {
            if (request.action == "auth")
            {
                auth(request.user, request.password);
            }

            else if (request.action == "register")
            {
                register(request.user, request.password);
            }

            else if (request.action == "show_cookie")
            {
                show_cookie();
            }

            else if (request.action == "get_all_passwords")
            {
                get_all_passwords();
            }
        }

        chrome.extension.onRequest.addListener(onRequest);
        </script>
    </body>
</html>
